package com.ruoyi.liborder.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.liborder.domain.LibOrderNote;
import com.ruoyi.liborder.service.ILibOrderNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 留言Controller
 *
 * @author kjleo
 * {@code @date} 2022-11-29
 */
@RestController
@RequestMapping("/lib/note")
public class NoteController extends BaseController {
    @Autowired
    private ILibOrderNoteService libOrderNoteService;

    /**
     * 查询留言列表
     */
    @PreAuthorize("@ss.hasPermi('lib:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibOrderNote libOrderNote) {
        startPage();
        List<LibOrderNote> list = libOrderNoteService.selectLibOrderNoteList(libOrderNote);
        return getDataTable(list);
    }

    /**
     * 导出留言列表
     */
    @PreAuthorize("@ss.hasPermi('lib:note:export')")
    @Log(title = "留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibOrderNote libOrderNote) {
        List<LibOrderNote> list = libOrderNoteService.selectLibOrderNoteList(libOrderNote);
        ExcelUtil<LibOrderNote> util = new ExcelUtil<LibOrderNote>(LibOrderNote.class);
        util.exportExcel(response, list, "留言数据");
    }

    /**
     * 获取留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('lib:note:query')")
    @GetMapping(value = "/{noteId}")
    public AjaxResult getInfo(@PathVariable("noteId") String noteId) {
        return AjaxResult.success(libOrderNoteService.selectLibOrderNoteByNoteId(noteId));
    }

    /**
     * 新增留言
     */
    @PreAuthorize("@ss.hasPermi('lib:note:add')")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibOrderNote libOrderNote) {
        return toAjax(libOrderNoteService.insertLibOrderNote(libOrderNote));
    }

    /**
     * 修改留言
     */
    @PreAuthorize("@ss.hasPermi('lib:note:edit')")
    @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibOrderNote libOrderNote) {
        return toAjax(libOrderNoteService.updateLibOrderNote(libOrderNote));
    }

    /**
     * 删除留言
     */
    @PreAuthorize("@ss.hasPermi('lib:note:remove')")
    @Log(title = "留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noteIds}")
    public AjaxResult remove(@PathVariable String[] noteIds) {
        return toAjax(libOrderNoteService.deleteLibOrderNoteByNoteIds(noteIds));
    }
}
